package org.example.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;


@Component
@Aspect
public class SysroleAdvice {

    @Pointcut("execution(* org.example.service.ResourcesService.*(..))")
    private void sysroleptx(){}

    @Around("SysroleAdvice.sysroleptx()")
    public Object trimStr(ProceedingJoinPoint pjp) throws Throwable {
        Object[] arrs = pjp.getArgs();
        for (int i=0;i<arrs.length;i++){
            // 判断参数是不是字符串,arrs[i].getClass()获取类型
            if(arrs[i].getClass().equals(String.class)){
                arrs[i] = arrs[i].toString().trim();
            }
        }
        Object ret = pjp.proceed(arrs);
        return ret;
    }

}
